/******************************************************************************\
 *                                                                            *
 *                         Craftmesh Project                                  *
 *                   Flavio Bertini fl.bertini@gmail.com                      *
 *                                                                            *
 *                                                                            *
\******************************************************************************/

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <GL/freeglut.h>
#include "Const.h"
#include "Leap.h"
#include "Craftmesh_model.h"
#include "Craftmesh_viewer.h"
#include "Craftmesh_controller.h"
#include <cmath>


using namespace Leap;
using namespace std;


// External Resources
extern vector<Mod_SubdivMesh> _mesh;
extern Vew_GlutWindow         _window;
extern Con_CraftmeshListener  _listener;
extern Controller             _controller;


int main(int argc, char** argv)
{
  // arguments check
  if (argc < 2)
  {
    cout << "Error: Enough argument, specify the filename. -> exit!!" << endl;
    exit(1);
  }
  else
  {
    _mesh.resize(argc-1);
    for (int i=0; i<argc-1; i++)
    {
      _mesh[i].mod_load(argv[i+1], "../data/");
      _mesh[i].color = GL_COLOR_V[i%GL_NUM_COLORA];
    }
  }


// FB: sezione temporanea dedicata al test delle booleane
char scelta;
cout << "Debug Test booleano? [s/n]: ";
// cin >> scelta;
scelta = 's';
if (scelta == 's')
{

  vector<Mod_SubdivMesh*> result = gen_applyBooleanOps(&(_mesh[0]),&(_mesh[1]));
  Mod_SubdivMesh tempMesh;

  printf("nVert:%d\n",result[0]->nVert);
  printf("nVert:%d\n",result[1]->nVert);
  printf("nVert:%d\n",result[2]->nVert);
  printf("nVert:%d\n",result[3]->nVert);

  result[0]->mod_copyMesh(&tempMesh);
  _mesh.push_back(tempMesh);
  result[1]->mod_copyMesh(&tempMesh);
  _mesh.push_back(tempMesh);
  result[2]->mod_copyMesh(&tempMesh);
  _mesh.push_back(tempMesh);
  result[3]->mod_copyMesh(&tempMesh);
  _mesh.push_back(tempMesh);
  printf("_mesh size %d \n",_mesh.size());

  // ...
  return 0;

}
// FB: fine sezione


  // add the listener to the controller in order to receive LEAP events
  _controller.addListener(_listener);

  // initialize GLUT environment and run
  _window.vew_initWindow(argc, argv);

  // remove the sample listener when done
  _controller.removeListener(_listener);

  return 0;
}
